﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ControlExplorer.Controls.Gauge
{
    public partial class RadialGauge : UserControl
    {
        Storyboard storyboard = new Storyboard();
        DoubleAnimation animation = new DoubleAnimation();
        Random r = new Random();

        public RadialGauge()
        {
            InitializeComponent();

            //Applies a random animation to show a more lively sample.
            animation.Duration = TimeSpan.FromSeconds(1);
            animation.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseInOut };
            Storyboard.SetTarget(animation, myGauge);
            Storyboard.SetTargetProperty(animation, new PropertyPath("(c1Gaugeauge.Value)"));
            storyboard.Children.Add(animation);
            storyboard.Completed += storyboard_Completed;
            storyboard.Begin();
        }

        void storyboard_Completed(object sender, EventArgs e)
        {
            animation.From = animation.To;
            animation.To = r.NextDouble() * 100;
            storyboard.Begin();
        }

        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            // stop storyboard at unloading
            storyboard.Completed -= new EventHandler(storyboard_Completed);
            storyboard.Stop();
        }
    }
}
